package com.fqh.utils;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;

import org.junit.Test;

import com.fqh.commons.utils.JsonUtils;
import com.fqh.manager.entity.TSysUser;

 
/**
* @author fqh 
* @version 创建时间：2018年1月2日 上午11:28:16
* 类说明
*/
public class JsonTest<T> {
	
	@Test
	public void test() throws NoSuchMethodException, SecurityException {
		TSysUser user = new TSysUser();
		user.setId(1);
		user.setUsername("make");
		user.setPassword("12123");
		user.setRegisttime(new Date());
		user.setEmail("729855417@qq.com");
		//System.out.println("user:"+JsonUtils.toJson(user));
		String struser = JsonUtils.toJson(user); 
		JsonTest<TSysUser> test= new JsonTest<TSysUser>();
		TSysUser user1 = test.parseToObject(struser);
		user1.toString();
		
	}
	@SuppressWarnings("unchecked")
	public T parseToObject(String jsonString) throws NoSuchMethodException, SecurityException {
		Class cls = this.getClass();  
        Method method = cls.getMethod("parseToObject", String.class);  
        Type[] type=  method.getGenericParameterTypes();  
        ParameterizedType t = (ParameterizedType)type[0];  
        System.out.println(t.getActualTypeArguments()[0]);//获得泛型class java.util.Date  
        System.out.println(t.getRawType());//获得原始类型。class java.util.Vector  
		//ParameterizedType type=  (ParameterizedType)this.getClass().getGenericSuperclass();
		//System.out.println(type.toString());
		//Class<T>  clz=(Class<T>)(((ParameterizedType)this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]);   
		//return JsonUtils.parse(jsonString,clz);
        return null;
	}
	
 
}
